<?php

require_once(sfConfig::get('sf_lib_dir').'/filter/base/BaseFormFilterPropel.class.php');

/**
 * Step filter form base class.
 *
 * @package    casesonline
 * @subpackage filter
 * @author     Your name here
 * @version    SVN: $Id: sfPropelFormFilterGeneratedTemplate.php 16976 2009-04-04 12:47:44Z fabien $
 */
class BaseStepFormFilter extends BaseFormFilterPropel
{
  public function setup()
  {
    $this->setWidgets(array(
      'order_nr'             => new sfWidgetFormFilterInput(),
      'source_id'            => new sfWidgetFormPropelChoice(array('model' => 'Source', 'add_empty' => true)),
      'multiple_question_id' => new sfWidgetFormPropelChoice(array('model' => 'MultipleQuestion', 'add_empty' => true)),
      'source_step_list'     => new sfWidgetFormPropelChoice(array('model' => 'Source', 'add_empty' => true)),
      'source_list'          => new sfWidgetFormPropelChoice(array('model' => 'MultipleAnswer', 'add_empty' => true)),
      'log_list'             => new sfWidgetFormPropelChoice(array('model' => 'Status', 'add_empty' => true)),
      'status_list'          => new sfWidgetFormPropelChoice(array('model' => 'Casus', 'add_empty' => true)),
    ));

    $this->setValidators(array(
      'order_nr'             => new sfValidatorSchemaFilter('text', new sfValidatorInteger(array('required' => false))),
      'source_id'            => new sfValidatorPropelChoice(array('required' => false, 'model' => 'Source', 'column' => 'id')),
      'multiple_question_id' => new sfValidatorPropelChoice(array('required' => false, 'model' => 'MultipleQuestion', 'column' => 'id')),
      'source_step_list'     => new sfValidatorPropelChoice(array('model' => 'Source', 'required' => false)),
      'source_list'          => new sfValidatorPropelChoice(array('model' => 'MultipleAnswer', 'required' => false)),
      'log_list'             => new sfValidatorPropelChoice(array('model' => 'Status', 'required' => false)),
      'status_list'          => new sfValidatorPropelChoice(array('model' => 'Casus', 'required' => false)),
    ));

    $this->widgetSchema->setNameFormat('step_filters[%s]');

    $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);

    parent::setup();
  }

  public function addSourceStepListColumnCriteria(Criteria $criteria, $field, $values)
  {
    if (!is_array($values))
    {
      $values = array($values);
    }

    if (!count($values))
    {
      return;
    }

    $criteria->addJoin(SourceStepPeer::STEP_ID, StepPeer::ID);

    $value = array_pop($values);
    $criterion = $criteria->getNewCriterion(SourceStepPeer::SOURCE_ID, $value);

    foreach ($values as $value)
    {
      $criterion->addOr($criteria->getNewCriterion(SourceStepPeer::SOURCE_ID, $value));
    }

    $criteria->add($criterion);
  }

  public function addSourceListColumnCriteria(Criteria $criteria, $field, $values)
  {
    if (!is_array($values))
    {
      $values = array($values);
    }

    if (!count($values))
    {
      return;
    }

    $criteria->addJoin(SourcePeer::STEP_ID, StepPeer::ID);

    $value = array_pop($values);
    $criterion = $criteria->getNewCriterion(SourcePeer::MULTIPLE_ANSWER_ID, $value);

    foreach ($values as $value)
    {
      $criterion->addOr($criteria->getNewCriterion(SourcePeer::MULTIPLE_ANSWER_ID, $value));
    }

    $criteria->add($criterion);
  }

  public function addLogListColumnCriteria(Criteria $criteria, $field, $values)
  {
    if (!is_array($values))
    {
      $values = array($values);
    }

    if (!count($values))
    {
      return;
    }

    $criteria->addJoin(LogPeer::STEP_ID, StepPeer::ID);

    $value = array_pop($values);
    $criterion = $criteria->getNewCriterion(LogPeer::STATUS_ID, $value);

    foreach ($values as $value)
    {
      $criterion->addOr($criteria->getNewCriterion(LogPeer::STATUS_ID, $value));
    }

    $criteria->add($criterion);
  }

  public function addStatusListColumnCriteria(Criteria $criteria, $field, $values)
  {
    if (!is_array($values))
    {
      $values = array($values);
    }

    if (!count($values))
    {
      return;
    }

    $criteria->addJoin(StatusPeer::STEP_ID, StepPeer::ID);

    $value = array_pop($values);
    $criterion = $criteria->getNewCriterion(StatusPeer::CASUS_ID, $value);

    foreach ($values as $value)
    {
      $criterion->addOr($criteria->getNewCriterion(StatusPeer::CASUS_ID, $value));
    }

    $criteria->add($criterion);
  }

  public function getModelName()
  {
    return 'Step';
  }

  public function getFields()
  {
    return array(
      'id'                   => 'Number',
      'fase_id'              => 'ForeignKey',
      'order_nr'             => 'Number',
      'source_id'            => 'ForeignKey',
      'multiple_question_id' => 'ForeignKey',
      'source_step_list'     => 'ManyKey',
      'source_list'          => 'ManyKey',
      'log_list'             => 'ManyKey',
      'status_list'          => 'ManyKey',
    );
  }
}
